﻿namespace MobileTrack.Web
{
    using System.Data.Entity;
    using System.Diagnostics.CodeAnalysis;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using System.Web.Optimization;
    using System.Web.Routing;
    using MobileTrack.Core.Data;
    using MobileTrack.Core.Migrations;

    [ExcludeFromCodeCoverage]
    public class MobileTrackApplication : HttpApplication
    {
        internal const string ConnectionStringName = "MobileTrackDb";

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            Database.SetInitializer(
                new MigrateDatabaseToLatestVersion<MobileTrackContext, MobileTrackConfiguration>(ConnectionStringName));

            // Force database initializer.
            using (var context = new MobileTrackContext(ConnectionStringName))
            {
                context.Celulares.FirstOrDefault();
            }
        }
    }
}